package com.palominocia.capa_datos_nodoCentral.dbPostgreSQL.schema1.modelo.seguridad;
import javax.persistence.Column;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;

import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord;
import org.springframework.roo.addon.jpa.entity.RooJpaEntity;
import org.springframework.roo.addon.tostring.RooToString;

@RooJavaBean
@RooToString
@RooJpaEntity(entityName="schema1.Usuario", schema = "capa_datos_nodo")
@RooJpaActiveRecord(persistenceUnit = "persistenceUnitPostgres")
public class Usuario {
	
    /**
     */
    @NotNull
    @Column(name = "username", unique = true)
    private String username;

    /**
     */
    @NotNull
    private String password;

    /**
     */
    @NotNull
    private String email;

    /**
     */
    @NotNull
    private String habilitado;

    @Transient
	public static Usuario findNombreUsuario(String username) {
    	Usuario user=null;
    	try {
    		user=entityManager().createQuery("SELECT o FROM Usuario o WHERE o.username =:username ",Usuario.class)
    				.setParameter("username", username)
    				.getSingleResult();
		} catch (Exception e) {
			user=null;
		}
		return user;
	}

}
